<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
      
        var str = 'abcdacbabcbababcbabcabd'
        var arr=str.split("")
      function fn(str,arr){
        var res=arr.reduce(function(pre,cur){
            if(cur in pre){
                pre[cur] += 1
            }else {
                pre[cur] = 1
            }
            return pre
        },{})
        for (var key in res) {
            console.log(key + '出现的次数' + res[key]);
        }
      }
      fn(str,arr)
       
    </script>
</body>
</html>